package com.controller;

import java.util.ArrayList;

import com.domain.AppUser;
import com.domain.Location;
import com.persistence.LocationAccessObject;

public class LocationManager {
	private LocationAccessObject locationDAO;
	
	public LocationManager(){
		locationDAO = new LocationAccessObject();
	}
	
	public void registerLocation(Location location){
		locationDAO.insertObject(location);
	}
	
	public boolean locationAlreadyExists(String locationName,String username){
		Location loc = locationDAO.getObject(locationName);
		boolean alreadyExists = false;
		if(loc != null){
			if(loc.getLocationUser().equals(username)){
				alreadyExists = true;
			}
		}
		return alreadyExists;
	}
	
	public void updateLocation(String appUser,String locationRealName,String locationName,double locationRadius){
		locationDAO.setAppUser(appUser);
		locationDAO.updateObject(locationRealName,locationName,locationRadius);
	}
	
	public void deleteLocation(String appUsername,String locationName){
		locationDAO.setAppUser(appUsername);
		locationDAO.deleteLocation(locationName);
	}
	public ArrayList<Location> getLocationsList(AppUser user){
		locationDAO.setAppUser(user.getUserName());
		ArrayList<Location> userLocations = locationDAO.getObjects();
		return userLocations;
	}
}
